package cn.tedu.micro.demo.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 在配置类中 创建bean对象 准备组件信息
 */
@Configuration
public class DeclareConfiguration {
    //声明交换机 demo_ex direct demo_queue 绑定交换机使用 demo_rk
    @Bean
    public Queue demoQueue(){
        //channel.queueDelare(名字,持久化,独立专属,自动删除,其他参数)
        //1.直接new queue
        //new Queue("demo_queue",false,false,false,null);
        //2.使用构建器
        return QueueBuilder.nonDurable("demo_queue").build();
    }
    @Bean
    public Exchange demoExchange(){
        //channel.exchangeDeclare(名字,类型,其他)
        //1.直接new
        //return new DirectExchange("demo_ex",false,false,null);
        return ExchangeBuilder.directExchange("demo_ex").build();
    }
    @Bean
    public Binding demoBinding(){
        //channel.queueBind(队列名,交换机名,路由key)
        return BindingBuilder.bind(demoQueue()).to(demoExchange()).with("demo_rk").noargs();
    }
}
